package Thread;

public class Dom9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            //Thread.currentThread()-->t
            //这个代码是在lambda方法当中调用的,返回的就是t
            //判断线程是否终止
            while (!Thread.currentThread().isInterrupted()){//true
                System.out.println("hello therad");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //e.printStackTrace();
                    break;
                }
            }
        });
        t.isDaemon();
        t.start();
        //这个代码是在main方法当中调用的，此时返回的结果就是main
        //System.out.println("main: "+Thread.currentThread().getName());
      Thread.sleep(3000);
        //主动去终止线程
        System.out.println("main线程尝试终止t线程");
      /*  t.interrupt();*/

    }
}
